<template>
    <view class="goods-item" @click="itemClickHandler">
      <!-- 商品左侧图片区域 -->
      <view class="goods-item-left">
        <!-- 选中框 -->
        <radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioChangeHandler"></radio>
        <image class="goods-image" :src="goods.goods_small_logo || defaultPic "></image>
      </view>
      <!-- 商品右侧信息区域 -->
      <view class="goods-item-right">
        <!-- 商品标题 -->
        <view class="goods-name">{{goods.goods_name}}</view>
        <!-- 商品价格 -->
        <view class="goods-price-box">
          <view class="goods-price">¥{{ goods.goods_price | fixedTwo('123')}}</view>
          <!-- <view class="goods-price">¥{{Number(goods.goods_price).toFixed(2)}}</view> -->   
          <!-- <view class="goods-price">¥{{fixed(goods.goods_price)}}</view> -->
          <!-- <view class="goods-price">¥{{fixed2}}</view> -->
          <uni-number-box :min="1" :value="goods.goods_count" @change="numChangeHandler" v-if="showNumBox" ></uni-number-box>
        </view>
      </view>
    </view>
</template>

<script>
  export default {
    name:"my-goods",
    data() {
      return {
        // 无图片适配
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    // 过滤器 格式化处理显示
    filters: {
      fixedTwo(num, arg2){
        console.log(num, arg2)
        return Number(num).toFixed(2)
      }
    },
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNumBox: {
        type: Boolean,
        default: false
      }
    },
    computed:{
      fixed2(){
        return Number(this.goods.goods_price).toFixed(2)
      }
    },
    methods: {
      fixed(num){
        return Number(num).toFixed(2)
      },
      itemClickHandler(){
        this.$emit('xxx', this.goods)
      },
      radioChangeHandler(e){
        console.log(e)
        this.$emit('radio-change', {
          goods_id: this.goods.goods_id,
          goods_state: this.goods.goods_state
        })
      },
      numChangeHandler(value){
        console.log(value)
        this.$emit('num-change', {
          goods_id: this.goods.goods_id,
          goods_count: value
        })
      }
    }
  }
</script>

<style lang="scss">

    .goods-item {
      display: flex;
      border-bottom: 1px solid #efefef;
      padding: 8rpx;
      // align-items: center;
      .goods-item-left {
        display: flex;
        align-items: center;
        .goods-image {
          width: 200rpx;
          height: 200rpx;
          vertical-align: middle;
        }
      }
      .goods-item-right {
        display: flex;
        // flex: 1;
        flex-direction: column;
        justify-content: space-between;
        
        .goods-name {
          font-size: 24rpx;
        }
        
        .goods-price-box {
          display: flex;
          align-items: center;
          justify-content: space-between;
          
          .goods-price{
            font-size: 32rpx;
            color: #c00000;
          }
        }
      }
    }
  
</style>
